/***********************************************************************
 * Module:  NeuralNetwork.java
 * Author:  Mladen
 * Purpose: Defines the Class NeuralNetwork
 ***********************************************************************/

package raf.neural;

import java.util.Vector;

import raf.core.NetworkLayerInterface;

public class NeuralNetwork extends raf.core.AbstractNetwork {
	public NeuralNetwork(String _config) {
		String[] numbers = _config.split("-");
		layersNo = numbers.length - 1;
		layers = new int[layersNo + 1];
		for (int i = 0; i < layersNo + 1; i++) {
			layers[i] = Integer.parseInt(numbers[i]);
		}

		// System.out.print(layersNo);
		// for (int n : layers) {
		// System.out.print("-" + n);
		// }
	}

	public int layersNo;

	public int layers[];
	
	public Double[] inputs;

	public void initialize() {
		networkLayerInterface = new Vector<NetworkLayerInterface>();
		StandardNetworkLayer layer;
		for (int i = 1; i < layersNo; i++) {
			layer = new StandardNetworkLayer(layers[i], layers[i - 1], false);
			layer.initialize();
			networkLayerInterface.add(layer);
		}
		layer = new StandardNetworkLayer(layers[layersNo],
				layers[layersNo - 1], true);
		layer.initialize();
		networkLayerInterface.add(layer);
	}
	
	public void epoch() {
		((Vector<NetworkLayerInterface>)networkLayerInterface).get(0).propagateLayer(inputs);
	}

	public String toString() {
		StringBuffer buffer = new StringBuffer();
		for (NetworkLayerInterface layer : networkLayerInterface) {
			buffer.append(layer);
			buffer.append("\n");
		}
		return buffer.toString();
	}
}